package com.moly.grpc.client;

import com.moly.grpc.routeguide.Feature;
import com.moly.grpc.routeguide.Point;
import com.moly.grpc.routeguide.RouteGuideGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.CharBuffer;
import java.util.concurrent.TimeUnit;

public class GrpcClient {


    public static void main(String[] args) throws InterruptedException {
/*
        ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8999).usePlaintext().build();
        RouteGuideGrpc.RouteGuideBlockingStub routeGuideBlockingStub = RouteGuideGrpc.newBlockingStub(channel);


        Point request = Point.newBuilder().setLongitude(100).setLatitude(100).build();
        Feature feature = routeGuideBlockingStub.getFeature(request);

        System.out.println(feature.toString());
        channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);*/
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        CharBuffer charBuffer = CharBuffer.allocate(256);
//        new HeapCharBufferR();

        while (true){

            try {
                charBuffer.clear();
                int read = inputStreamReader.read(charBuffer);

                if(read !=-1){
                    charBuffer.flip();
                    String res=charBuffer.toString();
                    System.out.println(res);
                    if(res.equals("nmb\n")){
                        System.out.println("再见");
                        charBuffer = null;
                        inputStreamReader.close();
                        break;

                    }else{
                        System.out.println(12);

                    }

                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
        

    }
}
